package top.kaoshanji.u1ch11b.controllers;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.kaoshanji.u1ch11b.model.Payment;
import top.kaoshanji.u1ch11b.proxy.PaymentsProxy;

import java.util.UUID;
import java.util.logging.Logger;

/**
 * 代码清单-u1ch11b-229页b：注入和使用OpenFeign客户端
 * @author kaoshanji
 * ^_^
 * create time 2025/5/1 15:22
 */
@RestController
public class PaymentsController {

    private static Logger logger = Logger.getLogger(PaymentsController.class.getName());

    private final PaymentsProxy paymentsProxy;

    public PaymentsController(PaymentsProxy paymentsProxy) {
        this.paymentsProxy = paymentsProxy;
    }

    @PostMapping("/createPaymentOpenFeign")
    public Payment createPaymentOpenFeign(@RequestBody Payment payment) {

        String requestId = UUID.randomUUID().toString();

        logger.info("请求ID：" + requestId + "；支付金额：" + payment.getAmount());

        // 发起一个远程调用
        return paymentsProxy.createPayment(requestId, payment);

    }

}
